package com.nf.practice.listoperate;

import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.Test;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.concurrent.TimeUnit;

public class ListToString {

    @Test
    public void test4() {
        Long a1 = new Long(1);
        Long a2 = new Long(2);
        Long a3 = new Long(3);
        List<Long> months = new ArrayList<>();
        months.add(a1);
        months.add(a2);
        months.add(a3);
        System.out.println(months.stream().allMatch(month -> month < 12) ? "1" : "0");
    }

    @Test
    public void test3() {
        Date date1 = new Date(); // 假设这是第一个日期
        Date date2 = new Date(System.currentTimeMillis() + TimeUnit.DAYS.toMillis(45)); // 假设这是第二个日期，比当前日期晚45天

        long diff = differenceInDaysDividedBy30(date1, date2);
        System.out.println("相差的天数除以30向下取整的结果是: " + diff);
    }

    public long differenceInDaysDividedBy30(Date startDate, Date endDate) {
        // Java 8及以后版本推荐使用java.time包中的类进行日期时间操作
        // 将Date转换为Instant
        Instant start = startDate.toInstant();
        Instant end = endDate.toInstant();

        // 计算相差的天数
        long daysBetween = ChronoUnit.DAYS.between(start, end);

        // 除以30并向下取整
        long result = Math.floorDiv(daysBetween, 30);
        return result;
    }

    @Test
    public void test2() {

        List<BigDecimal> tds = new ArrayList<>();
        tds.add(BigDecimal.ZERO);
        Integer a = 5;
        tds.add(new BigDecimal(a));
        if (!CollectionUtils.isEmpty(tds)) {
            System.out.println("11111");
            System.out.println(tds);
        } else {
            System.out.println("22222222");
        }

        List<BigDecimal> rh_loancur_due_balanceList = new ArrayList<>();
        String x = rh_loancur_due_balanceList.stream().anyMatch(value -> value.compareTo(BigDecimal.valueOf(4000)) > 0) ? "1" : "0";
        System.out.println(x);
    }

    @Test
    public void test() {
        //String类型的集合转换成string
        List<String> stringList = new ArrayList<>();
        stringList.add("1");
        stringList.add("2");
        stringList.add("3");
        stringList.add("4");
        System.out.println(stringList);
        String string = StringUtils.join(stringList,",");
        System.out.println(string);

    }
}
